package org.gd.hellojaxb.privat24.other;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.List;

@XmlRootElement(name = "news")
public class NewsList {

    @XmlRootElement(name = "news")
    public static class News {
        private int id;
        private int parentId;
        private int refState;
        private String state;
        private String subj;
        private String msgBody;
        private int parentNewsId;
        private int owner;
        private String date;
        private String signature;

        public News() {
            id = 0;
            parentId = 0;
            refState = 0;
            state = "";
            subj = "";
            msgBody = "";
            parentNewsId = 0;
            owner = 0;
            date = "";
            signature = "";
        }

        public News(int id, int parentId, int refState, String state, String subj, String msgBody, int parentNewsId, int owner, String date, String signature) {
            this.id = id;
            this.parentId = parentId;
            this.refState = refState;
            this.state = state;
            this.subj = subj;
            this.msgBody = msgBody;
            this.parentNewsId = parentNewsId;
            this.owner = owner;
            this.date = date;
            this.signature = signature;
        }

        public int getId() {
            return id;
        }
        @XmlAttribute(name = "id")
        public void setId(int id) {
            this.id = id;
        }

        public int getParentId() {
            return parentId;
        }
        @XmlAttribute(name = "par_id")
        public void setParentId(int parentId) {
            this.parentId = parentId;
        }

        public int getRefState() {
            return refState;
        }
        @XmlAttribute(name = "refstate")
        public void setRefState(int refState) {
            this.refState = refState;
        }

        public String getState() {
            return state;
        }
        @XmlAttribute(name = "state")
        public void setState(String state) {
            this.state = state;
        }

        public String getSubj() {
            return subj;
        }
        @XmlAttribute(name = "subj")
        public void setSubj(String subj) {
            this.subj = subj;
        }

        public String getMsgBody() {
            return msgBody;
        }
        @XmlAttribute(name = "msg_body")
        public void setMsgBody(String msgBody) {
            this.msgBody = msgBody;
        }

        public int getParentNewsId() {
            return parentNewsId;
        }
        @XmlAttribute(name = "par_news_id")
        public void setParentNewsId(int parentNewsId) {
            this.parentNewsId = parentNewsId;
        }

        public int getOwner() {
            return owner;
        }
        @XmlAttribute(name = "owner")
        public void setOwner(int owner) {
            this.owner = owner;
        }

        public String getDate() {
            return date;
        }
        @XmlAttribute(name = "date")
        public void setDate(String date) {
            this.date = date;
        }

        public String getSignature() {
            return signature;
        }
        @XmlAttribute(name = "signature")
        public void setSignature(String signature) {
            this.signature = signature;
        }
    }

    private List<News> newsList = new ArrayList<News>();

    public NewsList() {
        add(0, 0, 0, "", "", "", 0, 0, "", "");
        add(0, 0, 0, "", "", "", 0, 0, "", "");
        add(0, 0, 0, "", "", "", 0, 0, "", "");
    }

    public List<News> getNewsList() {
        return newsList;
    }

    @XmlElement(name = "item")
    public void setNewsList(List<News> newsList) {
        this.newsList = newsList;
    }

    public void add(News news) {
        getNewsList().add(news);
    }

    public void add(int id, int parentId, int refState, String state, String subj, String msgBody, int parentNewsId, int owner, String date, String signature) {
        getNewsList().add(new News(id, parentId, refState, state, subj, msgBody, parentNewsId, owner, date, signature));
    }
}
